package com.funny.controller;

import com.funny.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author Ming
 * @description
 * @fileSimpleName OrderSentinelTestController
 * @fileName com.funny.controller.OrderSentinelTestController
 * @date 2024年07月02日 18:40
 */
@Slf4j
@RefreshScope
@RestController
@RequestMapping(value = "/orders")
public class OrderSentinelTestController {
    @Value("${test.info}")
    private String testInfo;

    @Autowired
    private RedisService redisService;

    @RequestMapping("/add")
    public String add() {
        log.info("下单成功");
        String message = redisService.getCacheObject("Ming");
        return "Hello World :7022 sentinel服务：" + System.currentTimeMillis() + message + testInfo;
    }


    @RequestMapping("/queryFlow")
    public String queryFlow() {
        return "正常访问sentinel服务";
    }

    @RequestMapping("/queryFlowThread")
    public String queryFlowThread() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        log.info("正常访问sentinel服务");
        return "正常访问sentinel服务";
    }


    @RequestMapping("/get")
    public String get() {
        return "查询订单";
    }


    /**
     * 热点规则
     */
    @RequestMapping("/queryErr")
    public String queryErr() {
        int a = 1 / 0;
        return "hello";
    }

    /**
     * 热点规则
     */
    @RequestMapping("/get/{id}")
    public String hotBlockHandler(@PathVariable String id) throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        return "热点异常处理";
    }
}
